/// <summary>
/// Copyright 2010 Ivo Limmen (ivo@limmen.org)
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
/// 
/// http://www.apache.org/licenses/LICENSE-2.0
/// 
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
/// </summary>

using System;
using Services.Configuration.Api;
using ServiceController.Api;
using System.IO;

namespace Services.Configuration
{
	public class ConfigService : BaseService, IConfigService
	{
		private const string CONFIGURATION_DIRECTORY = "Config";

		private string configurationDirectory;

		public ConfigService() : base("ConfigService", "Service that provides configuration.")
		{
			this.configurationDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CONFIGURATION_DIRECTORY);
		}

		public override string[] GetRequiredServices()
		{
			return new string[] { "LogService" };
		}

		#region IConfigService implementation

		public string GetSetting(string appName, string hostname, string section, string key)
		{
			ConfigurationLoader loader = new ConfigurationLoader(this.configurationDirectory, appName);
			ConfigurationReader reader = new ConfigurationReader(loader);
			
			IResolver resolver = reader.Read();
			
			return resolver.GetSetting(hostname, section, key);
		}
		
		#endregion
	}
}
